//动作顺序为：>,>>,<<,<, multSelect-multSelect
function initMultiSelect(afterFun) {
	$.each($("div.multSelectDiv"), function(i, el) {
		var fromId = $(el).attr("fromSelect");
		var toId = $(el).attr("toSelect");
		// console.log($("#"+toId).)
		$(el).find("a").each(function(j, aObj) {
			// var $selected = $("#attrListSelect option:selected");
			$(aObj).click(function() {
				var $selectedFrom = $("#" + fromId + " option:selected");
				var $allFrom = $("#" + fromId + " option");
				var $selectedTo = $("#" + toId + " option:selected");
				var $allTo = $("#" + toId + " option");
				switch (j) {
				case 0:
					$selectedFrom.remove().appendTo($("#" + toId));
					break;
				case 1:
					$allFrom.remove().appendTo($("#" + toId));
					break;
				case 2:
					$allTo.remove().appendTo($("#" + fromId));
					break;
				case 3:
					$selectedTo.remove().appendTo($("#" + fromId));
					break;
				default:
					break;
				}
				if (typeof afterFun == "function") {
					// 改变后执行的方法
					afterFun();
				}
			});
		});
	});
}

// 动作顺序为：>,>>,<<,<, multSelect-table
function initSelectToTable(optionToTr, trToOption,afterFun) {
	$.each($("div.multSelectDiv"), function(i, el) {
		var fromId = $(el).attr("fromSelect");
		var toId = $(el).attr("toSelect");
		// console.log($("#"+toId).)
		$(el).find("a").each(function(j, aObj) {
			// var $selected = $("#attrListSelect option:selected");
			$(aObj).click(function() {
				var $selectedFrom = $("#" + fromId + " option:selected");
				var $allFrom = $("#" + fromId + " option");
				var $selectedTo = $("#" + toId + " tr.selected");
				var $allTo = $("#" + toId + " tr:gt(1)");
				switch (j) {
				case 0:
					$selectedFrom.remove();
					optionToTr($selectedFrom).appendTo($("#" + toId));
					break;
				case 1:
					$allFrom.remove();
					optionToTr($allFrom).appendTo($("#" + toId));
					break;
				case 2:
					$allTo.remove();
					trToOption($allTo).appendTo($("#" + fromId));
					break;
				case 3:
					$selectedTo.remove();
					trToOption($selectedTo).appendTo($("#" + fromId));
					break;
				default:
					break;
				}
				if (typeof afterFun == "function") {
					// 改变后执行的方法
					afterFun();
				}
			});
		});
	});
}